<?php
namespace app\admin\controller;

use app\admin\widget\Name;
use app\common\cache\bank\IBankCache;
use app\common\cache\bank\IBankTypeCache;
use app\common\cache\common\IAreaCache;
use app\common\cache\credit\ICreditCache;
use app\common\cache\credit\ICreditFavoriteCache;
use app\common\cache\credit\ICreditRecommendCache;
use app\common\cache\credit\ICreditTagCache;
use app\common\controller\AdminBaseController;
use app\common\enum\CreditStatus;
use app\common\enum\HtmlEnumValue;
use app\common\enum\IsDelete;
use app\common\ext\IDb;
use app\common\ext\ILog;
use app\common\ext\IRequest;
use think\Db;

class CreditApplicationRecord extends AdminBaseController{
    /**
     * @功能：信用卡申请记录列表
     * @开发者：cxl
     * @return string
     */
    public function credit_apply_list(){
        //接收参数
        $credit_apply_id = IRequest::get('credit_apply_id');
        $user_id = IRequest::get("user_id");
        $nick = IRequest::get("nick");
        $real = IRequest::get("real");
        $credit_product_id = IRequest::get('credit_product_id');
        $credit_product_name = IRequest::get('credit_product_name');
        $area = IRequest::get("area");

        //整理区域数据
        $province_id = 0;
        $city_id = 0;
        if(!empty($area) && is_array($area)){
            if(!empty($area[0])) $province_id = $area[0]; //取得省份
            if(!empty($area[1])) $city_id = $area[1]; //取得城市
        }

        $credit_apply_where = null;
        if (!empty($credit_apply_id)) $credit_apply_where['ca.credit_apply_id'] = $credit_apply_id;
        if (!empty($user_id)) $credit_apply_where['ca.user_id'] = $user_id;
        if(!empty($nick))$credit_apply_where['us.nick'] = array("like","%{$nick}%");
        if(!empty($real))$credit_apply_where['us.real'] = array("like","%{$real}%");
        if (!empty($credit_product_id)) $credit_apply_where['ca.credit_product_id'] = $credit_product_id;
        if(!empty($credit_product_name))$credit_apply_where['cp.credit_product_name'] = array("like","%{$credit_product_name}%");
        if (!empty($province_id)) $credit_apply_where['ca.province_id'] = $province_id;
        if (!empty($city_id)) $credit_apply_where['ca.city_id'] = $city_id;
        $credit_apply_list = IDb::getInstance('credit_apply as ca')
            ->setDbFiled('ca.*,cp.credit_product_name,us.nick,us.real')
            ->setDbJoin('user as us','us.user_id=ca.user_id')
            ->setDbJoin('credit_product as cp','cp.credit_product_id=ca.credit_product_id')
            ->setDbWhere($credit_apply_where)
            ->setDbOrder('credit_apply_id desc')
            ->pag();
        if ($credit_apply_list === false){
            error('获取申请记录失败');
        }

        //取得属性分类列表
        $area_list = IAreaCache::getAllList(2);

        //页面赋值
        $this->assign("credit_apply_id",$credit_apply_id);
        $this->assign("user_id",$user_id);
        $this->assign("nick",$nick);
        $this->assign("real",$real);
        $this->assign("credit_product_id",$credit_product_id);
        $this->assign("credit_product_name",$credit_product_name);
        $this->assign("area",$area);
        $this->assign("area_list",$area_list);
        $this->assign("credit_apply_list",$credit_apply_list);

        return view();
    }

    /**
     * @功能：信用卡申请详情
     * @开发者：cxl
     * @return string
     */
    public function credit_apply_info(){
        //接收参数
        $credit_apply_id = IRequest::get("credit_apply_id",IRequest::NOT_EMPTY,"返佣编号不能为空！");

        //取得日志
        $credit_apply_where['credit_apply_id'] = $credit_apply_id;
        $credit_apply_info = IDb::getInstance('credit_apply')->setDbWhere($credit_apply_where)->row();
        if(empty($credit_apply_info)){
            error("信用卡申请信息失败！");
        }

        //设置layout
        $this->layout("layout_empty");

        //页面赋值
        $this->assign("credit_apply_id",$credit_apply_id);
        $this->assign("credit_apply_info",$credit_apply_info);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：信用卡申请日志
     * @开发者：cxl
     * @return string
     */
    public function credit_apply_log(){
        //接收参数
        $credit_apply_id = IRequest::get("credit_apply_id",IRequest::NOT_EMPTY,"信用卡编号不能为空！");

        //取得日志
        $where['credit_apply_id'] = $credit_apply_id;
        $credit_apply_log_list = IDb::getInstance('credit_apply_log')->setDbWhere($where)->setDbOrder("credit_apply_log_id desc")->pag();

        //设置layout
        $this->layout("layout_empty");

        //页面赋值
        $this->assign("credit_apply_log_list",$credit_apply_log_list);

        //渲染模板输出
        return view();
    }
}